
import datetime
import string
import time
import random
from dao.iotdbhelper import Iot

iot=Iot()
# 构造江阴隧道左洞passiofo数据
def create_passinfo(location,num,timestamp=None):
    sql_statements = []
    id=484+num
    current_timestamp=int(time.time()*1000)
    today_timestamp = current_timestamp- (random.randint(0, 8) * 3600 * 1000)
    objectClass=random.randint(1, 10)
    time_num=random.randint(45000, 145000)
    color=random.randint(1, 7)
    if location=="jyright":
        lane=random.randint(1, 3)
    else:
        lane=random.randint(4, 6)
    plate="湘" + random.choice(string.ascii_uppercase[:8]) +''.join(random.choices(string.ascii_uppercase + string.digits, k=5))

    if timestamp==None:
        sql=f'INSERT INTO root.jingjiang.passinfo.{location}(time,id,objectClass,lane,plate,stakeMark,counter,enterTime,outTime,avgSpeed,passTime,plateColor,outStakeMark,color) VALUES({today_timestamp+time_num},{id},{objectClass},{lane},\'{plate}\',"LK2+100",1,{today_timestamp},{today_timestamp+time_num},63.2,{time_num},{color},"LK5+370",{color})'
    else:
        yesterday_current_timestamp=int(time.time()*1000)- (24 * 3600 * 1000)
        yesterday_timestamp=yesterday_current_timestamp- (random.randint(0, 8) * 3600 * 1000)
        sql=f'INSERT INTO root.jingjiang.passinfo.{location}(time,id,objectClass,lane,plate,stakeMark,counter,enterTime,outTime,avgSpeed,passTime,plateColor,outStakeMark,color) VALUES({yesterday_timestamp+time_num},{id},{objectClass},{lane},\'{plate}\',"LK2+100",1,{yesterday_timestamp},{yesterday_timestamp+time_num},63.2,{time_num},{color},"LK5+370",{color})'
    sql_statements.append(sql)
    return sql_statements

n1=random.randint(30, 80)
n2=random.randint(100, 180)
n3=random.randint(100, 180)
n4=random.randint(30, 80)
for i in range(n1):
    sql_statements = create_passinfo('jyleft',num=i)   # 左洞jyleft 今日数据
    for sql in sql_statements:
        iot.non_search(sql)
time.sleep(2)
for i in range(n2):
    sql_statements = create_passinfo('jyleft',num=i,timestamp=1)   # 右洞jyleft 昨日数据
    for sql in sql_statements:
        iot.non_search(sql)
time.sleep(2)
for i in range(n3):
    sql_statements = create_passinfo('jyright',num=i)   # 右洞jyright 今日数据
    for sql in sql_statements:
        iot.non_search(sql)
time.sleep(2)
for i in range(n4):
    sql_statements = create_passinfo('jyright',num=i,timestamp=1)   # 右洞jyright  昨日数据
    for sql in sql_statements:
        iot.non_search(sql)